package mapred.task.example;

import java.io.IOException;
import java.util.Iterator;

import mapred.task.extention.TextReducer;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

public class AggregationReducer extends TextReducer {

	@Override
	public void reduce(Text key, Iterator<Text> values,
			OutputCollector<Text, Text> output, Reporter reporter)
			throws IOException {
		StringBuilder sb = new StringBuilder();
		while (values.hasNext()) {
			sb.append("\t");
			sb.append(values.next().toString());
		}
		String value = sb.toString();
		if (value.isEmpty()) {
			output.collect(key, new Text(""));
		} else {
			output.collect(key, new Text(value.substring(1)));
		}
	}

    @Override
    protected void setUp() {
    }

}
